#include <iostream>
#include <malloc.h>
#include <ctime>
#include <cstdlib>

using namespace std;

#define MAXSIZE 10

typedef struct  DLNode
{
	int data;	//数据域
	struct DLNode *pRior;	//前驱结点
	struct DLNode *pNext;	//后继结点
}DLNode, *PDLNode;

void createDlistR(PDLNode&,int[],int);	//尾插法建立新的双链表
void traverseList(PDLNode);	//遍历

int main(void)
{
	srand((unsigned)time(NULL));

	int a[MAXSIZE];
	PDLNode L;
	for(int i = 0; i <MAXSIZE; i++)
	{
		a[i] = rand()%101;
	}

	createDlistR(L,a,MAXSIZE);
	traverseList(L);

	cout << "hello list" << endl;
	return 0;
}

//尾插法创建双链表
void createDlistR(PDLNode &L, int a[], int n)
{
	PDLNode s, r;
	int i;
	L = (PDLNode)malloc(sizeof(DLNode));
	L->pNext = NULL;
	L->pRior = NULL;
	r = L;
	for(int i = 0; i < n; i++)
	{
		s = (PDLNode)malloc(sizeof(DLNode));
		s->data = a[i];

		r->pNext = s;
		s->pRior = r;
		r = s;
	}
	r->pNext = NULL;
}

//遍历
void traverseList(PDLNode L)
{
	if(L->pNext == 0)
	{
		cout << "链表为空" << endl;
	}
	else
	{
		while (L->pNext != 0)
		{
			cout << L->pNext->data <<" ";
			L = L->pNext;
		}
	}
	cout << endl;
}